/* -*- C++ -*- */

//=============================================================================
/*
 * @author Feloweria <380374483@qq.com>
 * Copyright (C) Feloweria
 * 
 * $ID 2013-07-08 03:41:08 PM
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * @version 1.0
 */
//=============================================================================

#ifndef FELOWRIA_STRING_CONVERTOR_INCLUDE
#define FELOWRIA_STRING_CONVERTOR_INCLUDE

#include "Felowria.h"
#include "Base/String.h"
#include "Base/Type.h"

FELOWRIA_BEGIN

template<typename Type>
class StringConvertor
{
public:
	typedef BaseString<Type>					String;
	typedef Type								Encode;
	
public:
#define CONVERT_DECLARE(TYPE,NAME) \
	static TYPE			To##NAME(const Encode *string);	\
	static bool			Is##NAME(const String &string);	\
	static TYPE			To##NAME(const String &string);	\
	static bool			Is##NAME(const Encode *string);	\
	static String		ToString(const TYPE value); \
	static Encode*		ToString(Encode *buf, int32 size, const TYPE value); \

	CONVERT_DECLARE(int8, Int8)
	CONVERT_DECLARE(uint8, UInt8)
	CONVERT_DECLARE(int16, Int16)
	CONVERT_DECLARE(uint16, UInt16)
	CONVERT_DECLARE(int32, Int32)
	CONVERT_DECLARE(uint32, UInt32)
	CONVERT_DECLARE(int64, Int64)
	CONVERT_DECLARE(uint64, UInt64)
	CONVERT_DECLARE(float, Float)
	CONVERT_DECLARE(double, Double)
	CONVERT_DECLARE(bool, Bool)
	
	
#undef STRING_CONVERT_TO_TYPE_DECLARE

private:
	static bool IsDigit(const Encode &encode);
	static bool IsNegative(const Encode &encode);
	static bool IsDemicalPoint(const Encode &encode);

private:
	static const Encode DIGIT_BEGIN;
	static const Encode DIGIT_END;
	
	static const Encode PLUS;
	static const Encode MINUTE;
	
	static const Encode DECIMAL_POINT;

	static const String TRUE_STRING[];
	static const String FALSE_STRING[];

	static const int BOOL_NUM;

}; // class StringConvertor

FELOWRIA_END


#include "Base/StringConvertor.inl"


#endif // FELOWRIA_STRING_CONVERTOR_INCLUDE
